import { createFFmpeg, fetchFile } from '@ffmpeg/ffmpeg'
import { ElMessageBox } from 'element-plus'

async function compressVideo (file, limit = 50 * 1024 * 1024) {
    const ffmpeg = createFFmpeg({
        corePath: 'ffmpeg-core.js',
        log: true,
        progress: ({ratio})=> {
            progress = `完成率:${(ratio * 100).toFixed(2)}%`
        }
      })
      const { name, size } = e.target.files[0]
      console.log('原大小', size)
      this.message = '正在加载\n'
      await ffmpeg.load()
      this.message = '开始压缩\n'
      ffmpeg.FS('writeFile', name, await fetchFile(e.target.files[0]))
      await ffmpeg.run('-i', name, '-b:v', '512k', 'output.mp4')
      this.message = '压缩完成'
      const data = ffmpeg.FS('readFile', 'output.mp4')
      this.video = URL.createObjectURL(new Blob([data.buffer], {
        type: 'video/mp4'
      }))
}